package cn.paul.wechatshop.common;

import com.google.common.collect.Sets;
import com.sun.org.apache.xml.internal.security.keys.keyresolver.implementations.PrivateKeyResolver;
import lombok.Data;
import lombok.Getter;

import javax.management.monitor.StringMonitor;
import java.util.Set;

/**
 * Created by Administrator on 2017/9/23 0023.
 *
 * @author Paul
 */
public class Const {

    public final static String CURRENT_USER = "currentUser";
    public final static String EMAIL = "email";
    public static final String USERNAME = "username";
    public final static String OPENID = "110110";

    @Getter
    public enum ProductStatusEnum {
        ON_SALE(0, "在售"), OFF_SALE(1, "售空");
        private int code;
        private String value;

        ProductStatusEnum(int code, String value) {
            this.code = code;
            this.value = value;
        }

    }

    //订单相关
    @Getter
    public enum OrderStatusEnum {
        CANCELED(0, "已取消"), NO_PAY(10, "未支付"),
        PAID(20, "已付款"),
        SHIPPED(30, "已发货"),
        ORDER_SUCCESS(40, "订单完成"), ORDER_CLOSED(50, "订单关闭");

        private int code;
        private String value;

        OrderStatusEnum(int code, String value) {
            this.code = code;
            this.value = value;
        }

        /**
         * 该静态方法可以根据枚举code获得枚举本身进而得到value
         *
         * @param code
         * @return OrderStatusEnum
         */
        public static OrderStatusEnum codeOf(int code) {
            for (OrderStatusEnum OrderStatusEnum : values()) {
                if (OrderStatusEnum.getCode() == code) {
                    return OrderStatusEnum;
                }
            }
            throw new RuntimeException("没有找到相应枚举");
        }


    }

    //支付状态
    @Getter
    public enum payStatus {
        WAIT(0, "等待支付"), SUCCESS(1, "支付成功");
        private int code;
        private String msg;

        payStatus(int code, String msg) {
            this.code = code;
            this.msg = msg;
        }
    }

    //订单支付常量
    @Getter
    public enum PayPlatformEnum {
        ALIPAY(1, "支付宝"), WECHAT(2, "微信支付");
        private int code;
        private String value;

        PayPlatformEnum(int code, String value) {
            this.code = code;
            this.value = value;
        }


    }

    @Getter
    public enum PaymentEnum {
        ONLINE_PAY(1, "在线支付");
        private int code;
        private String value;

        PaymentEnum(int code, String value) {
            this.code = code;
            this.value = value;
        }

        //该静态方法可以根据枚举code获得枚举本身进而得到value
        public static PaymentEnum codeOf(int code) {
            for (PaymentEnum paymentEnum : values()) {
                if (paymentEnum.getCode() == code) {
                    return paymentEnum;
                }
            }
            throw new RuntimeException("没有找到相应枚举");
        }
    }

    /**
     * 自定义异常的枚举
     */
    @Getter
    public enum ResultEnum {
        PRODUCT_NOT_EXITS(10, "商品不存在"),
        PRODUCT_STOCK_NOT_ENOUGH(20, "商品库存不足!"),
        ORDER_NOT_EXISTS(30,"订单不存在!"), ORDER_DETAIL_NOT_EXISTS(40,"订单详情为空")
        ,ORDER_STATUS_ERROR(50,"订单状态不正确")
        ,ORDER_UPDATE_FAILED(60,"订单更新失败")
        ,PARAM_ERROR(70,"参数不正确!"),
        CART_EMPTY(80,"购物车为空!"),
        ORDER_OWNER_ERROR(90,"该订单不属于当前用户");
        private Integer code;
        private String msg;

        ResultEnum(Integer code, String msg) {
            this.code = code;
            this.msg = msg;
        }
    }


    /**
     * Created by Administrator on 2017/9/23 0023.
     */
    @Getter
    public enum ResponseCode {
        SUCCESS(0, "SUCCESS"),
        ERROR(1, "ERROR"),
        NEED_LOGIN(10, "NEED_LOGIN"),
        ILLEGAL_ARGUMENT(2, "ILLEGAL_ARGUMENT");

        private final int code;
        private final String desc;

        ResponseCode(int code, String desc) {
            this.code = code;
            this.desc = desc;
        }
    }

    //此处设计一个接口作为一个role的分类使用
    public interface Role {
        //普通用户
        int ROLE_CUSTOMER = 0;
        //管理员
        int ROLE_ADMIN = 1;
    }

    public interface Cart {
        //定义购物车中商品选中状态
        int CHECKED = 1;
        int UN_CHECKED = 0;
        String LIMIT_NUM_FAIL = "LIMIT_NUM_FAIL";
        String LIMIT_NUM_SUCCESS = "LIMIT_NUM_SUCCESS";
    }

    public interface ProductListOrderBy {
        Set<String> PRICE_ASC_DESC = Sets.newHashSet("price_desc", "price_asc");
    }

    public interface AlipayCallBack {
        String TRADE_STATUS_WAIT_BUYER_PAY = "WAIT_BUYER_PAY";
        String TRADE_STATUS_TRADE_SUCCESS = "TRADE_SUCCESS";
        String RESPONSE_SUCCESS = "success";
        String RESPONSE_FAILED = "failed";
    }
}
